package DataBase;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Vector;

import DataObjects.BusinessMenuRightList;

public class AddNewBusinessMenu {
	
	private Vector<BusinessMenuRightList> menuDetails;
	private Vector<String> menuDetails1;
	private int i=0;
	private int statusRecipe;
	private int status=0;
	public AddNewBusinessMenu(Vector<BusinessMenuRightList> menuDetail,Vector<String> menuDetail1)
	{
		
		this.menuDetails=menuDetail;
		this.menuDetails1=menuDetail1;
		
	}
	


public void saveNewBusinessMenu()
{
	SQLConnection sc=new SQLConnection();
	
	
	try {
		    
		PreparedStatement ps2 = sc.getConnection().prepareStatement("INSERT INTO menu (Mid,Mname,Mprice,Mstatus,Mtype) values(?,?,?,?,'business');");	
		
		
		sc.getConnection().setAutoCommit(false);
		ps2.setString(1,(String) menuDetails1.get(0));
		ps2.setString(2,(String) menuDetails1.get(1));
		ps2.setString(3,(String) menuDetails1.get(2));
		ps2.setString(4,(String) menuDetails1.get(3));
		
		ps2.executeUpdate();
		sc.getConnection().commit();
		ps2.close();
		while(i<menuDetails.size())
		{
			PreparedStatement ps1 = sc.getConnection().prepareStatement("INSERT INTO recipe_in_menu (Mid,Rid,role,isSelectable,rquantity) values(?,?,?,?,?);");	
			
			sc.getConnection().setAutoCommit(false);
			ps1.setString(1,(String) menuDetails1.get(0));
			ps1.setString(2,Integer.toString( menuDetails.get(i).getRid()));
			ps1.setString(3,(String) menuDetails.get(i).getRole());
			
			if(menuDetails.get(i).getIsSelectable().equals("לבחירה")){
				statusRecipe=1;}
			if(menuDetails.get(i).getIsSelectable().equals("קבוע")){
				statusRecipe=0;	}
			ps1.setString(4,Integer.toString(statusRecipe));
			ps1.setInt(5, menuDetails.get(i).getQuantity());
			ps1.executeUpdate();
			sc.getConnection().commit();
			ps1.close();
			i++;
		}
		
			
			
			
				
				
			sc.getConnection().close();	
		status=1;		
	}
	
	catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	}





public int getStatus() {
	return status;
}





public void setStatus(int status) {
	this.status = status;
}
	

	
	
}

